package com.usian.login.lister;

import cn.hutool.core.util.RandomUtil;
import com.usian.third.code.AliCodeUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * 消费者
 */
@Service
public class RabbitLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RabbitListener(queues = "java-queue")//监听注解

    public void sendLoginCode(Message message,String phone)throws Exception{
        System.out.println("监听到有消息产生");
        AliCodeUtils aliCodeUtils =new AliCodeUtils();
       String code= RandomUtil.randomNumbers(6);//生成六位验证码
        aliCodeUtils.sendLoginCode(phone,code);//
        stringRedisTemplate.opsForValue().set(phone,code);//key是手机号  value：是验证码
//              过期设置
        stringRedisTemplate.expire(phone,5, TimeUnit.MINUTES);
    }


}
